package com.dousb.cloudlibrary.model.enums;


import lombok.Getter;
import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * AnnouncementStatusEnum
 *
 * @author 豆沙包
 * @version 1.0
 * @since 2025-10-10  21:10
 */
@Getter
public enum AnnouncementStatusEnum {

    Draft("草稿", 0),
    Published("已发布", 1);

    private final String text;
    private final int value;

    AnnouncementStatusEnum(String text, int value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<Integer> getValues() {
        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static AnnouncementStatusEnum getEnumByValue(Integer value) {
        if (ObjectUtils.isEmpty(value)) {
            return null;
        }
        for (AnnouncementStatusEnum anEnum : AnnouncementStatusEnum.values()) {
            if (anEnum.getValue() == value) {
                return anEnum;
            }
        }
        return null;
    }

}